/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cryptography;

import zorg.platform.RandomGenerator;
import java.util.Random;
import platform.TenorCryptoUtils;

/**
 *
 * @author Tomasz Nowak
 */
public class TenorRandomGenerator implements RandomGenerator
{
	Random random;

	protected TenorRandomGenerator()
	{
		random = new Random();
	}
	private static TenorRandomGenerator instance;

	public static TenorRandomGenerator getInstance()
	{
		if ( instance == null )
		{
			instance = new TenorRandomGenerator();
		}
		return instance;
	}

	@Override
	public void getBytes( byte[] data )
	{
		random.nextBytes(data);
	}

	@Override
	public void getBytes( byte[] data, int offset, int length )
	{
		random.nextBytes(TenorCryptoUtils.subArray(data, offset, length));
	}

	@Override
	public byte[] getBytes( int length )
	{
		byte[] bytes = new byte[length];
		random.nextBytes(bytes);
		return bytes;
	}

	@Override
	public int getInt()
	{
		return random.nextInt();
	}

	@Override
	public byte getByte()
	{
		return ( byte ) (random.nextInt(256) - 128);
	}
}
